package cn.echoedu.command;

import cn.echoedu.command.base.ExecuteParam;
import cn.echoedu.command.base.FailureParam;
import cn.echoedu.command.base.SuccessParam;
import cn.echoedu.constants.Role;
import cn.echoedu.entity.Student;
import cn.echoedu.entity.Teacher;
import cn.echoedu.util.L;

import com.google.gson.Gson;

public class LoginCommand extends BaseCommand{
	private final String T="LoginCommand--------------->";
	public void executeSuccess(SuccessParam successparam) {
		// TODO Auto-generated method stub
		final String M="executeSuccess";
		L.p(T+M);
		if(successparam.getParam() instanceof Student){
			L.p(T+M+"send to sudent");
			Student student=(Student)successparam.getParam();
			LoginSuccessResponse loginsuccessresponse=new LoginSuccessResponse();
			loginsuccessresponse.setToken(successparam.getToken());
			loginsuccessresponse.setUsernumber(student.getStudentnumber());
			loginsuccessresponse.setRole(Role.student);
			loginsuccessresponse.setName(student.getName());
			loginsuccessresponse.setRealname(student.getRealname());
			loginsuccessresponse.setSex(student.getSex());
			loginsuccessresponse.setBirthday(student.getBirtyday()+"");
			loginsuccessresponse.setEntrancetime(student.getEntrancetime()+"");
			loginsuccessresponse.setQq(student.getQq());
			loginsuccessresponse.setEmail(student.getEmail());
			loginsuccessresponse.setBaidunumber(student.getBaidunumber());
			loginsuccessresponse.setSinanumber(student.getSinanumber());
			loginsuccessresponse.setWechatnumber(student.getWechatnumber());
			loginsuccessresponse.setJob(student.getJob().getJobname());
			loginsuccessresponse.setJobcode(student.getJob().getJobcode());
			loginsuccessresponse.setDegress(student.getDegress().getDegressname());
			loginsuccessresponse.setDegresscode(student.getDegress().getDegressid());
			loginsuccessresponse.setImageurl(student.getImage().getImagesrc());
			loginsuccessresponse.setImagecode(student.getImage().getImageid());
			loginsuccessresponse.setPoliticalstatus(student.getPoliticalstatus()
					.getPoliticalstatusname());
			loginsuccessresponse.setPoliticalstatuscode(student.getPoliticalstatus()
					.getPoliticalstatuscode());
			loginsuccessresponse.setSchoolname(student.getAclass().getProfessional()
					.getDepartment().getSchool().getSchoolname());
			loginsuccessresponse.setSchoolcode(student.getAclass().getProfessional()
					.getDepartment().getSchool().getSchoolcode());
			loginsuccessresponse.setDepartment(student.getAclass().getProfessional()
					.getDepartment().getDepartname());
			loginsuccessresponse.setDepartmentcode(student.getAclass().getProfessional()
					.getDepartment().getDepartmentcode());
			loginsuccessresponse.setProfessional(student.getAclass().getProfessional()
					.getProfessionalname());
			loginsuccessresponse.setProfessionalcode(student.getAclass().getProfessional()
					.getProfessionalcode());
			loginsuccessresponse.setAclass(student.getAclass().getClassname());
            loginsuccessresponse.setAclasscode(student.getAclass().getClasscode());
			Gson gson=new Gson();
			String sendstr=gson.toJson(loginsuccessresponse);
			send(sendstr,successparam.getResponse());
		}else if(successparam.getParam() instanceof Teacher){
			L.p(T+M+"send to teacher");
			Teacher teacher=(Teacher)successparam.getParam();
			LoginSuccessResponse loginsuccessresponse=new LoginSuccessResponse();
			loginsuccessresponse.setToken(successparam.getToken());
			loginsuccessresponse.setUsernumber(teacher.getTeachernumber());
			loginsuccessresponse.setRole(Role.teacher);
			loginsuccessresponse.setName(teacher.getName());
			loginsuccessresponse.setRealname(teacher.getRealname());
			loginsuccessresponse.setSex(teacher.getSex());
			loginsuccessresponse.setBirthday(teacher.getBirthday()+"");
			loginsuccessresponse.setEntrancetime("");
			loginsuccessresponse.setQq(teacher.getQq());
			loginsuccessresponse.setEmail(teacher.getEmail());
			loginsuccessresponse.setBaidunumber(teacher.getBaidunumber());
			loginsuccessresponse.setSinanumber(teacher.getSinanumber());
			loginsuccessresponse.setWechatnumber(teacher.getWechatnumber());
			loginsuccessresponse.setJob(teacher.getJob().getJobname());
			loginsuccessresponse.setJobcode(teacher.getJob().getJobcode());
			loginsuccessresponse.setDegress(teacher.getDegress().getDegressname());
			loginsuccessresponse.setDegresscode(teacher.getDegress().getDegressid());
			loginsuccessresponse.setImageurl(teacher.getImage().getImagesrc());
			loginsuccessresponse.setImagecode(teacher.getImage().getImageid());
			loginsuccessresponse.setPoliticalstatus(teacher.getPoliticalstatus()
					.getPoliticalstatusname());
            loginsuccessresponse.setPoliticalstatuscode(teacher.getPoliticalstatus()
            		.getPoliticalstatuscode());
			loginsuccessresponse.setSchoolname(teacher.getSchool().getSchoolname());
			loginsuccessresponse.setSchoolcode(teacher.getSchool().getSchoolcode());
			loginsuccessresponse.setDepartment("");
			loginsuccessresponse.setDepartmentcode(0);
			loginsuccessresponse.setProfessional("");
			loginsuccessresponse.setProfessionalcode(0);
			loginsuccessresponse.setAclass("");
			loginsuccessresponse.setAclasscode(0);
			Gson gson=new Gson();
			String sendstr=gson.toJson(loginsuccessresponse);
			send(sendstr,successparam.getResponse());
		}
	}

	public void executeFailure(FailureParam failureparam) {
		// TODO Auto-generated method stub
		final String M="executeFailure*********>";
		L.p(T+M);
		LoginFailureResponse loginfailureresponse = new LoginFailureResponse();
		Gson gson = new Gson();
		String sendstr=gson.toJson(loginfailureresponse);
		send(sendstr,failureparam.getResponse());
	}

	public void execute(ExecuteParam executeparam) {
		// TODO Auto-generated method stub

	}
	private class LoginSuccessResponse{
		private int code=401;
		private String msg="Login Success";
		private String token;
		private String usernumber;
		private int role;
		private String name;
		private String realname;
		private String sex;
		private String birthday;
		private String entrancetime;
		private String examnieenumber;
		private String qq;
		private String email;
		private String baidunumber;
		private String sinanumber;
		private String wechatnumber;
		private String job;
		private int jobcode;
		private String classname;
		private int classcode;
		private String degress;
		private int degresscode;
		private String imageurl;
		private int imagecode;
		private String politicalstatus;
		private int politicalstatuscode;
		private String schoolname;
		private int schoolcode;
		private String department;
		private int departmentcode;
		private String professional;
		private int professionalcode;
		private String aclass;
		private int aclasscode;
		public int getCode() {
			return code;
		}
		public void setCode(int code) {
			this.code = code;
		}
		public String getMsg() {
			return msg;
		}
		public void setMsg(String msg) {
			this.msg = msg;
		}
		public String getToken() {
			return token;
		}
		public void setToken(String token) {
			this.token = token;
		}
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public String getRealname() {
			return realname;
		}
		public void setRealname(String realname) {
			this.realname = realname;
		}
		public String getSex() {
			return sex;
		}
		public void setSex(String sex) {
			this.sex = sex;
		}
		public String getBirthday() {
			return birthday;
		}
		public void setBirthday(String birthday) {
			this.birthday = birthday;
		}
		public String getEntrancetime() {
			return entrancetime;
		}
		public void setEntrancetime(String entrancetime) {
			this.entrancetime = entrancetime;
		}
		public String getExamnieenumber() {
			return examnieenumber;
		}
		public void setExamnieenumber(String examnieenumber) {
			this.examnieenumber = examnieenumber;
		}
		public String getQq() {
			return qq;
		}
		public void setQq(String qq) {
			this.qq = qq;
		}
		public String getEmail() {
			return email;
		}
		public void setEmail(String email) {
			this.email = email;
		}
		public String getBaidunumber() {
			return baidunumber;
		}
		public void setBaidunumber(String baidunumber) {
			this.baidunumber = baidunumber;
		}
		public String getSinanumber() {
			return sinanumber;
		}
		public void setSinanumber(String sinanumber) {
			this.sinanumber = sinanumber;
		}
		public String getWechatnumber() {
			return wechatnumber;
		}
		public void setWechatnumber(String wechatnumber) {
			this.wechatnumber = wechatnumber;
		}
		public String getJob() {
			return job;
		}
		public void setJob(String job) {
			this.job = job;
		}
		public String getClassname() {
			return classname;
		}
		public void setClassname(String classname) {
			this.classname = classname;
		}
		public String getDegress() {
			return degress;
		}
		public void setDegress(String degress) {
			this.degress = degress;
		}
		public String getImageurl() {
			return imageurl;
		}
		public void setImageurl(String imageurl) {
			this.imageurl = imageurl;
		}
		public String getPoliticalstatus() {
			return politicalstatus;
		}
		public void setPoliticalstatus(String politicalstatus) {
			this.politicalstatus = politicalstatus;
		}
		
		public String getUsernumber() {
			return usernumber;
		}
		public void setUsernumber(String usernumber) {
			this.usernumber = usernumber;
		}
		public int getRole() {
			return role;
		}
		public void setRole(int role) {
			this.role = role;
		}
		public int getSchoolcode() {
			return schoolcode;
		}
		public void setSchoolcode(int schoolcode) {
			this.schoolcode = schoolcode;
		}
		public String getSchoolname() {
			return schoolname;
		}
		public void setSchoolname(String schoolname) {
			this.schoolname = schoolname;
		}
		public String getDepartment() {
			return department;
		}
		public void setDepartment(String department) {
			this.department = department;
		}
		public String getProfessional() {
			return professional;
		}
		public void setProfessional(String professional) {
			this.professional = professional;
		}
		public String getAclass() {
			return aclass;
		}
		public void setAclass(String aclass) {
			this.aclass = aclass;
		}
		public int getJobcode() {
			return jobcode;
		}
		public void setJobcode(int jobcode) {
			this.jobcode = jobcode;
		}
		public int getClasscode() {
			return classcode;
		}
		public void setClasscode(int classcode) {
			this.classcode = classcode;
		}
		public int getDegresscode() {
			return degresscode;
		}
		public void setDegresscode(int degresscode) {
			this.degresscode = degresscode;
		}
		public int getImagecode() {
			return imagecode;
		}
		public void setImagecode(int imagecode) {
			this.imagecode = imagecode;
		}
		public int getPoliticalstatuscode() {
			return politicalstatuscode;
		}
		public void setPoliticalstatuscode(int politicalstatuscode) {
			this.politicalstatuscode = politicalstatuscode;
		}
		public int getDepartmentcode() {
			return departmentcode;
		}
		public void setDepartmentcode(int departmentcode) {
			this.departmentcode = departmentcode;
		}
		public int getProfessionalcode() {
			return professionalcode;
		}
		public void setProfessionalcode(int professionalcode) {
			this.professionalcode = professionalcode;
		}
		public int getAclasscode() {
			return aclasscode;
		}
		public void setAclasscode(int aclasscode) {
			this.aclasscode = aclasscode;
		}

	}
	private class LoginFailureResponse{
		private int code=-401;
		private String msg="Login Fail";
		public int getCode() {
			return code;
		}
		public void setCode(int code) {
			this.code = code;
		}
		public String getMsg() {
			return msg;
		}
		public void setMsg(String msg) {
			this.msg = msg;
		}

	}
}
